/**
 * @author ChuwxNTC
 * Class LocationService
 * Date created 2012-09-27
 */
package hcmute.pps.service;

import hcmute.pps.common.aidl.ILocationRemoteService;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

/**
 * @author ChuwxNTC
 * 
 */
public class LocationService extends Service {
	private static final String TAG = "LOCATIONSERVICE";

	public class ILocationRemoteServiceImpl extends ILocationRemoteService.Stub {
		private static final String TAG_ILRI = "LOCATIONSERVICE.REMOTE";

		public Location getLocation() throws RemoteException {
			Log.e(TAG_ILRI, "getLocation");

			LocationManager locationManager;
			String context = Context.LOCATION_SERVICE;
			locationManager = (LocationManager) getSystemService(context);
			String provider = LocationManager.GPS_PROVIDER;
			Location location = locationManager.getLastKnownLocation(provider);

			return location;
		}

		public Location getLastKnownLocation() throws RemoteException {
			Log.e(TAG_ILRI, "getLastKnownLocation");

			LocationManager locationManager;
			String context = Context.LOCATION_SERVICE;
			locationManager = (LocationManager) getSystemService(context);
			String provider = LocationManager.GPS_PROVIDER;
			Location location = locationManager.getLastKnownLocation(provider);

			return location;
		}
	}

	@Override
	public void onCreate() {
		Log.e(TAG, "onCreate");
		super.onCreate();
	}

	@Override
	public void onDestroy() {
		Log.e(TAG, "onDestroy");
		super.onDestroy();
	}

	@Override
	public void onStart(Intent intent, int startId) {
		Log.e(TAG, "onStart: " + intent.toString() + " - " + startId);
		super.onStart(intent, startId);
	}

	@Override
	public IBinder onBind(Intent intent) {
		Log.e(TAG, "onBind: " + intent.toString());
		return new ILocationRemoteServiceImpl();
	}
}
